fix contemporaneous sampling for wartortle#49
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements support for contemporaneous (cross-sectional) sampling in the wartortle simulation configuration by adding rho parameter handling to the database storage and analysis workflow.
Key changes:
- Adds rho parameter storage to the HDF5 database for contemporaneous sampling scenarios
- Creates new lenient XML template and wartortle configuration for contemporaneous sampling simulations
- Adds Python script to extract and analyze output distributions including rho values
Reviewed changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 18 comments.
Show a summary per file
| File | Description |
|---|---|
| main.py | Adds conditional storage of rho parameter to HDF5 database when contemporaneous sampling is enabled |
| src/remaster-template-contemporaneous.xml | Fixes indentation of rhoReaction element for consistency |
| src/remaster-template-contemporaneous-lenient.xml | New XML template for lenient contemporaneous sampling with higher population threshold |
| src/get_output_distributions.py | New analysis script to extract and report parameter distributions from HDF5 output, including rho handling |
| config/simulation-wartortle.json | New configuration file for wartortle simulation with contemporaneous sampling enabled |
| config/simulation-charmeleon-alt.json | Updates worker count and duration range parameters |
| .gitignore | Adds .DS_Store file patterns to ignore list |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import h5py | ||
| import numpy as np | ||
|
|
||
| #look at an hdf5 file, pull out present prevalence and cumulative incidence |
There was a problem hiding this comment.
Comments in Python should have a space after the hash character for readability. The comment style is inconsistent with standard Python conventions (PEP 8).
| r0_interval = np.percentile(all_r0_samples, [2.5, 97.5], weights=r0_weights, method='inverted_cdf') | ||
| print(f"R0: Median={r0_median:.4f}, 95% interval=({r0_interval[0]:.4f}, {r0_interval[1]:.4f})") | ||
|
|
||
| #net removal rate |
There was a problem hiding this comment.
Comments in Python should have a space after the hash character for readability. The comment style is inconsistent with standard Python conventions (PEP 8).
|
|
||
|
|
||
|
|
||
| #OUTPUT |
There was a problem hiding this comment.
Comments in Python should have a space after the hash character for readability. The comment style is inconsistent with standard Python conventions (PEP 8).
| data=sim["simulation_results"]["present_cumulative"], | ||
| ) | ||
|
|
||
| #put rho in database if doing contemporaneous sampling |
There was a problem hiding this comment.
The comment style is inconsistent with the rest of the codebase. Other comments in this file have a space after the hash character. This comment should follow the same convention.
| #put rho in database if doing contemporaneous sampling | |
| # put rho in database if doing contemporaneous sampling |
| net_removal_interval = np.percentile(all_net_removal_samples, [2.5, 97.5], weights=net_removal_weights, method='inverted_cdf') | ||
| print(f"Net Removal Rate: Median={net_removal_median:.4f}, 95% interval=({net_removal_interval[0]:.4f}, {net_removal_interval[1]:.4f})") | ||
|
|
||
| #sampling proportion |
There was a problem hiding this comment.
Comments in Python should have a space after the hash character for readability. The comment style is inconsistent with standard Python conventions (PEP 8).
| epidemic_duration_interval = np.percentile(epidemic_durations, [2.5, 97.5]) | ||
| print(f"Epidemic Duration: Median={epidemic_duration_median:.4f}, 95% interval=({epidemic_duration_interval[0]:.4f}, {epidemic_duration_interval[1]:.4f})") | ||
|
|
||
| #number of parameter changes |
There was a problem hiding this comment.
Comments in Python should have a space after the hash character for readability. The comment style is inconsistent with standard Python conventions (PEP 8).
|
|
||
| #put rho in database if doing contemporaneous sampling | ||
| if "rho" in sim["parameters"].keys(): | ||
| params_grp.create_dataset("rho", data=sim["parameters"]["rho"]["values"]) | ||
|
|
There was a problem hiding this comment.
This code block is incorrectly placed outside the 'with open(pf, "rb") as f:' context manager block (which ends at line 645). The variable 'sim' is defined inside that context, and 'params_grp' is created from data read inside that context. This code should be moved inside the with block before line 646, at the same indentation level as the other dataset creation code (lines 638-645).
| #put rho in database if doing contemporaneous sampling | |
| if "rho" in sim["parameters"].keys(): | |
| params_grp.create_dataset("rho", data=sim["parameters"]["rho"]["values"]) | |
| # put rho in database if doing contemporaneous sampling | |
| if "rho" in sim["parameters"]: | |
| params_grp.create_dataset( | |
| "rho", data=sim["parameters"]["rho"]["values"] | |
| ) |
There was a problem hiding this comment.
@thomaswilliams23 the other comment about how the rho is stored appears incorrect but I think copilot is correct on this one about the level of indentation. The sim value may not have the expected value outside of the context.
| sampling_prop_interval = np.percentile(all_sampling_prop_samples, [2.5, 97.5], weights=sampling_prop_weights, method='inverted_cdf') | ||
| print(f"Sampling Proportion: Median={sampling_prop_median:.4f}, 95% interval=({sampling_prop_interval[0]:.4f}, {sampling_prop_interval[1]:.4f})") | ||
|
|
||
| #rho if present |
There was a problem hiding this comment.
Comments in Python should have a space after the hash character for readability. The comment style is inconsistent with standard Python conventions (PEP 8).
| #HYPERPARAMS | ||
| print("\nHyperparameter Distributions:") | ||
|
|
||
| #epidemic duration |
There was a problem hiding this comment.
Comments in Python should have a space after the hash character for readability. The comment style is inconsistent with standard Python conventions (PEP 8).
| num_param_changes_interval = np.percentile(num_param_changes, [2.5, 97.5]) | ||
| print(f"Number of Parameter Changes: Median={num_param_changes_median:.4f}, 95% interval=({num_param_changes_interval[0]:.4f}, {num_param_changes_interval[1]:.4f})") | ||
|
|
||
| #change times |
There was a problem hiding this comment.
Comments in Python should have a space after the hash character for readability. The comment style is inconsistent with standard Python conventions (PEP 8).
No description provided.